<?php defined('SYSPATH') OR die('No direct access allowed.');

class Model_Album extends Model{
	private $album_table;
	private $genre_table;
	
 	public function __construct(){
		$this->album_table = 'albums';
		$this->genre_table = 'genres';
	}
	
	public function get_list()
	{
		$query = DB::query(Database::SELECT,'select albums.id as id,albums.name as name,albums.author as author from albums');
//		$this->db->select('albums.id as id,albums.name as name,albums.author as author, genres.name as genre');
//		$this->_db->select('albums.id as id,albums.name as name,albums.author as author');
		//$this->_db->from($this->album_table);
//		$this->_db->join($this->genre_table,'genres.id','albums.genre_id');
		$result = $query->execute();
		return $result->as_array();
	}
	
	public function read($id)
	{
		$this->db->where('id', $id);
		$query = $this->db->get($this->album_table);
		return $query->result_array();
	}
	 
	public function delete($id)
	{
		$this->db->delete($this->album_table, array('id' => $id));
	}
	 
	public function update($id,$data)
	{
		$this->db->update($this->album_table, $data, array('id' => $id));
	}
	 
	public function create($data)
	{
		$this->db->insert($this->album_table, $data);
	}
}
	
